/*
 *  Copyright (c) 2022 ZhuHai Jieli Technology Co.,Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include "los_config.h"
#include "los_debug.h"
#include "los_interrupt.h"
#include "los_task.h"
#include "los_tick.h"

#include "boot.h"

VOID InitTask(VOID)
{
    OHOS_SystemInit();

    while (1) {
        LOS_TaskDelay(200); /* 2000ms */
    }
}

extern UINTPTR HEAP1_BEGIN;
extern UINTPTR HEAP1_SIZE;
extern UINTPTR data_size;
extern UINTPTR data_addr;
extern UINTPTR data_begin;

VOID Start(VOID)
{
    UINT32 ret;
    ret = LOS_KernelInit();
    LOS_MemInit(&HEAP1_BEGIN, &HEAP1_SIZE);
    if (DeviceManagerStart()) {
        printf("[%s] No drivers need load by hdf manager!", __func__);
    }
    if (ret == LOS_OK) {

        UINT32 uwRet;
        UINT32 taskID1;
        UINT32 taskID2;
        TSK_INIT_PARAM_S stTask = {0};

        stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)InitTask;
        stTask.uwStackSize = 0x1000;
        stTask.pcName = "InitTask";
        stTask.usTaskPrio = 26; /* Os task priority is 6 */
        uwRet = LOS_TaskCreate(&taskID1, &stTask);
        if (uwRet != LOS_OK) {
            printf("InitTask create failed\n");
        }

        LOS_Start();
    }
}

